<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title>投票规则</title>

	<link rel="stylesheet" href="../css/bootstrap.min.css" />
	<link rel="stylesheet" href="../css/docs.css" />
	<link rel="stylesheet" href="../css/grid.css" />
	<link rel="stylesheet" href="../css/style.css" />
	<style type="text/css">
		body{
			background-image: url("../img/shinedotted.png");
		}
	</style>
</head>
<body>
	<div class="container">
		<jsp:include page="../include/header.jsp">
			<jsp:param name="tag" value="vote"/>
		</jsp:include>
		
		<div id="wrapper" class="grid clearfix">
			<ol id="repos"  style="margin: 0;">
				<s:iterator value="candidatelist" var="c">
				<li class="repo grid-1 javascript">
					<h2><s:property value="#c.name"/></h2>
					<div style="text-align: center;">
						<a href="/vote/student/candidate.jspx?id=<s:property value='#c.id'/>"><img src="<s:property value='#c.sites'/>" alt="<s:property value='#c.name'/>" width="100px" title="点击查看详细信息"/></a>
						<p style="font-size: 16px;"><s:property value="#c.college"/><br/><s:property value="#c.major"/></p>
						<strong>投票</strong>&nbsp;<input type="checkbox" value="<s:property value='#c.id'/>"/>	
					</div>
				</li>
				</s:iterator>
			</ol>
		</div>
		
		<div class="wall">
		    <div class="tabbable">
			    <ul class="nav nav-tabs">
			    <li class="active"><a href="#tab1" data-toggle="tab">学生投票</a></li>
			    <li><a href="#tab2" data-toggle="tab">教师投票</a></li>
			    </ul>
				<div class="tab-content">
			    <div class="tab-pane active" id="tab1">
			    	<form class="form-horizontal">
				    <fieldset>
				    <div class="control-group">
				    <label class="control-label" for="input01" style="width: 60px;">学号</label>
				    <div class="controls" style="margin-left: 80px;">
				    <input type="text" class="input-xlarge" id="input01" title="学号"/>
				    </div>
				    </div>

				    <div class="control-group">
				    <label class="control-label" for="input02" style="width: 60px;">密码</label>
				    <div class="controls" style="margin-left: 80px;">
				    <input type="text" class="input-xlarge" id="input02" title="密码"/>
				    </div>
				    </div>
				    </fieldset>
				    </form>
				    <button class="btn btn-primary span2" id="student" style="margin-left: 120px;">确认投票</button>
			    </div>
			    <div class="tab-pane" id="tab2">
			    	<form class="form-horizontal">
			    	<fieldset>
				    <div class="control-group">
				    <label class="control-label" for="input03" style="width: 60px;">教师号</label>
				    <div class="controls" style="margin-left: 80px;">
				    <input type="text" class="input-xlarge" id="input03" title="教师号"/>
				    </div>
				    </div>

				    <div class="control-group">
				    <label class="control-label" for="input04" style="width: 60px;">密码</label>
				    <div class="controls" style="margin-left: 80px;">
				    <input type="text" class="input-xlarge" id="input04" title="密码"/>
				    </div>
				    </div>
				    </fieldset>
				    </form>
				    <button class="btn btn-primary span2" id="teacher" style="margin-left: 120px;">确认投票</button>
			    </div>
			</div>
		</div>
		</div>
	<%@ include file="../include/footer.jsp"%>
	</div>
	
	<script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="../js/bootstrap.min.js"></script>
	
	<script type="text/javascript">
		$(function() {
			var length = 0;
			var min = 3;
			var max = 7;
			
			$("input:checkbox").click(function() {
				if(length < max) {
					length = $("input:checked").length;
				} else {
					alert("最大只能选7个");
					$(this).attr("checked", false);
				}
			});
			
			$("#student").click(function() {
				if(length < min) {
					alert("最少要选择3个");
					return;
				}
				
				var id = $("#input01").val().trim();
				var pwd = $("#input02").val().trim();
				
				if(id == "" || pwd == "") {
					alert("用户名和密码不能为空");
					return;
				}
				
				var selectItems = new Array();
				$("input:checked").each(function() {
					selectItems.push($(this).val());
				});
				var selectStr = selectItems.join(",");
				
				$.ajax({
					url : 'studentvote.jspx',
					type : 'POST',
					data : {
						id : id,
						pwd : pwd,
						vote : selectStr
					},
					success : function(msg) {
						if(msg == 1) {
							alert("ok");
						} else if(msg == -1) {
							alert("已投过票");
						} else if(msg == -2) {
							alert("ip");
						} else if(msg == -4) {
							alert("服务器");
						}
					}
				});
			});
		});
	</script>
</body>
</html>
